package com.sservice.service.service.impl;

import com.sservice.service.service.IComService;
import com.sservice.urp.dao.IComDao;
import com.sservice.urp.entity.Com;
import com.sservice.urp.vo.ComVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ComServiceImpl implements IComService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IComDao comDao;

    @Override
    public String getComIdByDomain(String domain) {
        Com com = comDao.queryOneByDomain(domain);
        if (com == null) {
            return "";
        }
        return com.getId().toString();
    }

    /**
     * 判断行政区
     *
     * @param region
     * @return
     */
    @Override
    public Com judgeRegion(String region) {

        ComVo comVo = new ComVo();
        List<Com> list = comDao.queryByPage(comVo);
        List<Com> result = list.stream().filter(item -> {
            String regionStr = item.getName().replaceAll("司法局", "");
             return regionStr.equals(region)||  region.indexOf(regionStr)>-1;
        }).collect(Collectors.toList());
        if (result.size() > 0) {
            return result.get(0);
        }
        return null;
    }

    @Override
    public List<Com> queryByPage(ComVo user) {
        return comDao.queryByPage(user);
    }


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return comDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Com record) {
        return comDao.insert(record);
    }

    @Override
    public int insertSelective(Com record) {
        return comDao.insertSelective(record);
    }

    @Override
    public Com selectByComName(String name) {
        return comDao.selectByComName(name);
    }

    @Override
    public Com selectByPrimaryKey(Integer id) {
        return comDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Com record) {
        return comDao.updateByPrimaryKeySelective(record);
    }


    @Override
    public int queryCount(ComVo user) {
        return comDao.queryCount(user);
    }
}
